﻿using System;

namespace Gert3D
{
  /// <summary>
  /// Rectangle is an axially aligned bounding box. It is defined by the boundaries
  /// left, top, right and bottom which are combined into the two points LeftTop and RightBottom.
  /// </summary>
  public struct Rectangle2
  {
    public double Left;
    public double Right;
    public double Top;
    public double Bottom;

    /// <summary>
    /// Creates a new rectangle defined by the given values.
    /// </summary>
    /// <param name="left">The left boundary of the rectangle.</param>
    /// <param name="top">The top boundary of the rectangle.</param>
    /// <param name="right">The right boundary of the rectangle.</param>
    /// <param name="bottom">The bottom boundary of the rectangle.</param>
    public Rectangle2(double left, double top, double right, double bottom)
    {
      Left = left;
      Right = right;
      Top = top;
      Bottom = bottom;
    }

    /// <summary>
    /// Gets the width of the rectangle by calculating <code>right - left</code>.
    /// </summary>
    public double Width
    {
      get { return Right - Left; }
    }

    /// <summary>
    /// Gets the height of the rectangle by calculating <code>bottom - top</code>.
    /// </summary>
    public double Height
    {
      get { return Bottom - Top; }
    }

    /// <summary>
    /// Calculates the center of rectangle.
    /// </summary>
    /// <returns>The center of the rectangle.</returns>
    public Point2 GetCenter()
    {
      return new Point2(Left + Width / 2, Top + Height / 2);
    }

  }
}
